package com.codeduck.bean.entity;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * BeanFullLifeCycle注入的配置类 见 {@link com.codeduck.bean.config.BeanFullLifeCycleConfig}
 *
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @createDate: 2021-12-23
 */
@Slf4j
public class BeanFullLifeCycle implements InitializingBean{

    private static String name;
    private int age;
    private String email;
    private String sex;


    static {
        name = "xxx";
        log.warn("Bean 的 # 静态代码块# 内静态属性赋值完毕");
    }

    {
        this.age = 10;
        log.warn("Bean 的 # 普通代码块 # 内非静态属性赋值完毕");
    }

    public BeanFullLifeCycle() {
        this.email = "email";
        log.warn("Bean 的 # 构造方法 # 内属性赋值完毕");
    }

    public void setSex(String s) {
        this.sex = s;
        log.warn("Bean 的 # 属性赋值方法setSex() # 调用完毕");
    }

    public void init() {
        log.warn("@Bean#initMethod 方法调用完毕");
    }

    public void  destroy() {
        log.warn("@Bean#destroy 方法调用完毕");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.warn("InitializingBean#afterPropertiesSet() # 调用完毕");
    }

    @PostConstruct
    public void postConstruct() {
        log.warn("@PostConstruct 修饰的方法调用完毕");
    }

    @PreDestroy
    public void preDestroy() {
        log.warn("@PreDestroy 修饰的方法调用完毕");
    }
}
